home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / tmacexception.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.3 KB  |  103 lines

  1. //    TMacException.h - Exception class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinnie Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #ifndef _H_TMACEXCEPTION
  18. #define _H_TMACEXCEPTION
  19.  
  20.  
  21.  
  22. // ______________________________________________________________________________
  23. // EXCEPTION CLASSES
  24.  
  25. class TMacException 
  26. {
  27. public:
  28.     TMacException(const OSStatus theError) :
  29.                     fMessage("NO MESSAGE SPECIFIED"), 
  30.                     fError(theError), 
  31.                     fFileName("NO FILE SPECIFIED"), 
  32.                     fLineNumber(0L) 
  33.                     {};
  34.  
  35.     TMacException(const  char *theMessage, const OSStatus theError) :
  36.                     fMessage(theMessage), 
  37.                     fError(theError), 
  38.                     fFileName("NO FILE SPECIFIED"), 
  39.                     fLineNumber(0L) 
  40.                     {};
  41.                     
  42.     TMacException(const  char *theMessage, const OSStatus theError, const char *theFileName, const long theLineNumber) :
  43.                     fMessage(theMessage), 
  44.                     fError(theError), 
  45.                     fFileName(theFileName), 
  46.                     fLineNumber(theLineNumber) 
  47.                     {};
  48.                     
  49.     const char*             GetExceptionMessage(void)     { return fMessage;};
  50.     const OSStatus        GetExceptionErr(void)            { return fError;};
  51.     const char*                GetExceptionFile(void)        { return fFileName;};
  52.     const long                GetExceptionLine(void)        { return fLineNumber;};
  53.     
  54. protected:
  55.     const OSStatus     fError;
  56.     const  char*         fMessage;
  57.     const char*         fFileName;
  58.     const long            fLineNumber;
  59. };
  60.  
  61.  
  62. // Utility Macros
  63.  
  64. #define ThrowIfNil( _val_ )                                        \
  65.         if ( (_val_) == nil )                                        \
  66.             throw TMacException( "UNEXPECTED NIL RETURNED" ,0 , __FILE__, __LINE__)     
  67.  
  68. #define ThrowIfNotNil( _val_ )                                                \
  69.         if ( (_val_) != nil )                                                    \
  70.             throw TMacException( "EXPECTED NIL" ,0 , __FILE__, __LINE__) 
  71.  
  72. #define ThrowIfMacErr(_err_)                                        \
  73.         { OSErr _temp_ = (_err_);    \
  74.         if ( _temp_ != noErr)                                            \
  75.             throw TMacException( "NO MESSAGE SPECIFIED",  _temp_ , __FILE__, __LINE__);     }  
  76.  
  77. #define ThrowMacErr(_err_)                                                \
  78.             throw TMacException( "NO MESSAGE SPECIFIED", (_err_), __FILE__, __LINE__)     
  79.  
  80. #define ThrowMacErrIfNil( _val_, _err_  )                                        \
  81.         if ( (_val_) == nil )                                        \
  82.             throw TMacException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)     
  83.  
  84. #define ThrowMsgIfMacErr(_err_, _Msg_)                                        \
  85.         if ((_err_) != noErr)                                            \
  86.             throw TMacException( (_Msg_), (_err_), __FILE__, __LINE__)     
  87.  
  88. #define ThrowMsgMacErr(_err_, _Msg_)                                        \
  89.             throw TMacException( (_Msg_), (_err_), __FILE__, __LINE__)     
  90.  
  91. #define ThrowMsg( _Msg_)                                        \
  92.             throw TMacException( (_Msg_), noErr, __FILE__, __LINE__)     
  93.  
  94. #define ThrowMsgIfNot( _cond_, _Msg_)            \
  95.             if( ! (_cond_) )                                                    \
  96.             throw TMacException( (_Msg_), noErr, __FILE__, __LINE__)     
  97.  
  98. #define ThrowMsgIf( _cond_, _Msg_)            \
  99.             if( _cond_ )                                                    \
  100.             throw TMacException( (_Msg_), noErr, __FILE__, __LINE__)     
  101.             
  102. #endif
  103.